home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume4 / bidding < prev    next >
Encoding:
Internet Message Format  |  1988-04-29  |  21.5 KB

  1. Path: uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games
  2. From: games@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v04i018:  bidding - bridge bidding program
  5. Message-ID: <2580@tekred.TEK.COM>
  6. Date: 31 May 88 15:56:22 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 770
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted by: nathan@eddie.mit.edu (Nathan Glasser)
  12. Comp.sources.games: Volume 4, Issue 18
  13. Archive-name: bidding
  14.  
  15.     [This program lets you practice your bridge bidding by working
  16.      with and against yourself. -br]
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 1 (of 1)."
  25. # Contents:  README MANIFEST bidding.c bidding.doc bidding.h deal.c
  26. #   makefile
  27. # Wrapped by billr@saab on Tue May 31 08:57:45 1988
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f README -a "${1}" != "-c" ; then 
  30.   echo shar: Will not over-write existing file \"README\"
  31. else
  32. echo shar: Extracting \"README\" \(1388 characters\)
  33. sed "s/^X//" >README <<'END_OF_README'
  34. Xfrom the "bidding.doc" file:
  35. X
  36. X            Bridge Bidder Version 1.0
  37. X------------------------------------------------------------------------------
  38. XCopyright 1988 by Nathan Glasser.
  39. XYou may feel free to distribute this program in its current form.
  40. XPlease do not remove this copyright information.
  41. X==============================================================================
  42. XThis program lets you practice your bidding and opening leads.
  43. X
  44. XAny conventions you want to use are allowed because you're your own
  45. Xpartner, as well as your own opponents. The idea behind this program
  46. Xis that if you're involved with a large enough number of boards, you
  47. Xhopefully won't remember all the hands of a given board, and so you
  48. Xcan bid each of the four hands at different times. What the program
  49. Xdoes is let you make all the bids in all the hands, one bid at a
  50. Xtime, choosing which board to use at any point randomly and letting
  51. Xyou enter the next bid in its bidding sequence.
  52. X
  53. XIn this way, you get to practice bidding with 3 other players whose
  54. Xbidding you understand completely and a partner whom you trust
  55. Ximplicitly. If you find this not to be the case, then you'll probably
  56. Xhave discovered ways in which you need to better understand your
  57. Xbidding system or in which bidding can otherwise be improved.
  58. X
  59. X            by Nathan Glasser
  60. X            nathan@xx.lcs.mit.edu (internet)
  61. X            nathan@mit-eddie.uucp (usenet)
  62. X
  63. X            May, 1988
  64. END_OF_README
  65. if test 1388 -ne `wc -c <README`; then
  66.     echo shar: \"README\" unpacked with wrong size!
  67. fi
  68. # end of overwriting check
  69. fi
  70. if test -f MANIFEST -a "${1}" != "-c" ; then 
  71.   echo shar: Will not over-write existing file \"MANIFEST\"
  72. else
  73. echo shar: Extracting \"MANIFEST\" \(324 characters\)
  74. sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
  75. X   File Name        Archive #    Description
  76. X-----------------------------------------------------------
  77. X MANIFEST                  1    This shipping list
  78. X README                    1    
  79. X bidding.c                 1    
  80. X bidding.doc               1    
  81. X bidding.h                 1    
  82. X deal.c                    1    
  83. X makefile                  1    
  84. END_OF_MANIFEST
  85. if test 324 -ne `wc -c <MANIFEST`; then
  86.     echo shar: \"MANIFEST\" unpacked with wrong size!
  87. fi
  88. # end of overwriting check
  89. fi
  90. if test -f bidding.c -a "${1}" != "-c" ; then 
  91.   echo shar: Will not over-write existing file \"bidding.c\"
  92. else
  93. echo shar: Extracting \"bidding.c\" \(9272 characters\)
  94. sed "s/^X//" >bidding.c <<'END_OF_bidding.c'
  95. X/* bidding.c */
  96. X/*
  97. X            Bridge bidder
  98. X            by Nathan Glasser
  99. X            nathan@xx.lcs.mit.edu (internet)
  100. X            nathan@mit-eddie.uucp (usenet)
  101. X
  102. X            May, 1988
  103. X------------------------------------------------------------------------------
  104. XCopyright 1988 by Nathan Glasser.
  105. XYou may feel free to distribute this program in its current form.
  106. XPlease do not remove this copyright information.
  107. X*/
  108. X
  109. X#include "bidding.h"
  110. X
  111. Xint num_hands = 10;
  112. X
  113. Xchar *vuln_relative[] = {"YOUR SIDE","OTHER SIDE"};
  114. Xchar *vuln_absolute[] = {"1ST SIDE","2ND SIDE","NEITHER SIDE","BOTH SIDES"};
  115. Xchar *suit_strings[4] = {"SPADES","HEARTS","DIAMONDS","CLUBS"};
  116. Xchar *vuln_format[2][2] = {
  117. X  {"DECLARER SIDE","DEFENDER SIDE"},
  118. X  {"VERTICAL SIDE","HORIZONTAL SIDE"}};
  119. X
  120. X#define PASSED_OUT(pdeal) \
  121. X    ((pdeal)->num_bids == 4 && (pdeal)->bids->bid.suit == PASS)
  122. X
  123. Xmain(argc,argv)
  124. Xint argc;
  125. Xchar **argv;
  126. X{
  127. X    deal *deals;
  128. X    int i,j;
  129. X    int num_hands_left;
  130. X    int hand_num;
  131. X
  132. X    if (argc > 1)
  133. X    num_hands = atoi(argv[1]);
  134. X    printf("Dealing %d hands...\n",num_hands_left = num_hands);
  135. X
  136. X    deals = (deal *)malloc(num_hands * sizeof(deal));
  137. X
  138. X    srandom((unsigned)time(NULL));
  139. X
  140. X    for (i = 0; i < num_hands; i++)
  141. X    deal_hands(&deals[i]);
  142. X
  143. X    /* Accept bids */
  144. X    while (num_hands_left)
  145. X    {
  146. X    hand_num = random() % num_hands;
  147. X
  148. X    if (deals[hand_num].bidding_done)
  149. X        continue;
  150. X    for (i = 0; i < 24; i++)
  151. X        putchar('\n');
  152. X    print_bidding(stdout,&deals[hand_num]);
  153. X    printf("YOUR HAND (%s VULNERABLE):\n",
  154. X      (deals[hand_num].vulnerability <= RELATIVE) ?
  155. X      vuln_relative[(deals[hand_num].num_bids & 1) ^ 
  156. X      deals[hand_num].vulnerability] :
  157. X      vuln_absolute[deals[hand_num].vulnerability]);
  158. X    print_hand(stdout,deals[hand_num].hands[deals[hand_num].num_bids % 4]);
  159. X    while(accept_bid(&deals[hand_num]))
  160. X        printf("Bad bid.\n");
  161. X    if (deals[hand_num].bidding_done)
  162. X    {
  163. X        num_hands_left--;
  164. X        /* If hand was passed out */
  165. X        if (PASSED_OUT(&deals[hand_num]))
  166. X            display_complete_deal(&deals[hand_num],0);
  167. X    }
  168. X    }
  169. X
  170. X    /* Accept opening leads */
  171. X    for (hand_num = 0; hand_num < num_hands; hand_num++)
  172. X    {
  173. X        /* Make sure hand wasn't passed out */
  174. X    if (PASSED_OUT(&deals[hand_num]))
  175. X        continue;
  176. X    for (i = 0; i < 24; i++)
  177. X        putchar('\n');
  178. X    print_bidding(stdout,&deals[hand_num]);
  179. X    j = figure_out_leader(&deals[hand_num]);
  180. X    printf("YOUR HAND (%s VULNERABLE):\n",
  181. X      (deals[hand_num].vulnerability <= RELATIVE) ?
  182. X      vuln_relative[(j & 1) ^ 
  183. X      deals[hand_num].vulnerability] :
  184. X      vuln_absolute[deals[hand_num].vulnerability]);
  185. X    print_hand(stdout,deals[hand_num].hands[j]);
  186. X    while (get_lead(&deals[hand_num],j))
  187. X        printf("Bad lead.\n");
  188. X    display_complete_deal(&deals[hand_num],((j + 1) % 4));
  189. X    }
  190. X
  191. X    printf("All bidding complete.\n");
  192. X}
  193. X
  194. Xdisplay_complete_deal(pdeal,top_hand)
  195. Xdeal *pdeal;
  196. Xint top_hand;
  197. X{
  198. X    print_complete_deal(stdout,pdeal,top_hand);
  199. X    more();
  200. X    log_deal(pdeal,top_hand);
  201. X}
  202. X
  203. Xprint_complete_deal(fp,pdeal,top_hand)
  204. XFILE *fp;
  205. Xdeal *pdeal;
  206. Xint top_hand;
  207. X{
  208. X    int i;
  209. X    char top_h[4][80],left_h[4][80],right_h[4][80],bottom_h[4][80];
  210. X
  211. X    format_hand(top_h,pdeal->hands[top_hand]);
  212. X    format_hand(right_h,pdeal->hands[(top_hand + 1) % 4]);
  213. X    format_hand(bottom_h,pdeal->hands[(top_hand + 2) % 4]);
  214. X    format_hand(left_h,pdeal->hands[(top_hand + 3) % 4]);
  215. X    fprintf(fp,"\t\t\tCOMPLETE DEAL (%s VULNERABLE):\n",
  216. X      ((pdeal->vulnerability <= RELATIVE) ?
  217. X      vuln_format[PASSED_OUT(pdeal)][(top_hand & 1) ^ pdeal->vulnerability] :
  218. X      vuln_absolute[pdeal->vulnerability]));
  219. X
  220. X    for (i = 0; i < 4; i++)
  221. X        fprintf(fp,"\t\t\t%s\n",top_h[i]);
  222. X    for (i = 0; i < 4; i++)
  223. X        fprintf(fp,"%-43s%s\n",left_h[i],right_h[i]);
  224. X    for (i = 0; i < 4; i++)
  225. X        fprintf(fp,"\t\t\t%s\n",bottom_h[i]);
  226. X}
  227. X
  228. Xprint_bidding(fp,pdeal)
  229. XFILE *fp;
  230. Xdeal *pdeal;
  231. X{
  232. X    bid *bids;
  233. X    static char *bid_suits[] = {"S","H","D","C","N","DB","RD","P"};
  234. X    int bid_num = 0;
  235. X
  236. X    fprintf(fp,"BIDDING:\n");
  237. X    for (bids = pdeal->bids; bid_num < pdeal->num_bids; bids = bids->next)
  238. X    {
  239. X    if (bids->bid.suit <= RANK_USED)
  240. X        fprintf(fp,"\t%d %s",bids->bid.rank,bid_suits[bids->bid.suit]);
  241. X    else
  242. X        fprintf(fp,"\t%s",bid_suits[bids->bid.suit]);
  243. X    if ((++bid_num % 4) == 0)
  244. X        putc('\n',fp);
  245. X    }
  246. X    if (bid_num % 4)
  247. X    putc('\n',fp);
  248. X}
  249. X
  250. Xaccept_bid(pdeal)
  251. Xdeal *pdeal;
  252. X{
  253. X    int ch;
  254. X    int rank = -1,suit;
  255. X    bid *newbid;
  256. X    static int suit_cvt[] = {3,2,1,0,4};
  257. X    bid *tmp;
  258. X    int i;
  259. X    
  260. X    printf("\nEnter your bid: ");
  261. X
  262. X    /* Get optional rank */
  263. X    while (isspace(ch = getchar()));
  264. X
  265. X    if (isdigit(ch))
  266. X    {
  267. X    rank = ch - '0';
  268. X    while (isspace(ch = getchar()));
  269. X    }
  270. X
  271. X    /* Get suit, notrump, pass, double, or redouble */
  272. X    if (islower(ch))
  273. X    ch = toupper(ch);
  274. X
  275. X    switch (ch)
  276. X    {
  277. X    case 'S':
  278. X        suit = SPADES;
  279. X        break;
  280. X    case 'H':
  281. X        suit = HEARTS;
  282. X        break;
  283. X    case 'D':
  284. X        suit = (rank >= 0) ? DIAMONDS : DOUBLE;
  285. X        break;
  286. X    case 'C':
  287. X        suit = CLUBS;
  288. X        break;
  289. X    case 'N':
  290. X        suit = NOTRUMP;
  291. X        break;
  292. X    case 'P':
  293. X        suit = PASS;
  294. X        break;
  295. X    case 'R':
  296. X        suit = REDOUBLE;
  297. X        break;
  298. X    default:
  299. X        suit = -1;
  300. X        break;
  301. X    }
  302. X
  303. X    while (getchar() != '\n');
  304. X    if (suit < 0)
  305. X    return(1);
  306. X
  307. X    /* Make sure numerical bid is ok */
  308. X    if (suit <= RANK_USED)
  309. X    {
  310. X        if (rank < 1 || rank > 7)
  311. X        return(1);
  312. X    if (pdeal->num_bids > 0)
  313. X        for (tmp = pdeal->bids->prev,i = pdeal->num_bids; i;
  314. X          tmp = tmp->prev, i--)
  315. X        if (tmp->bid.suit <= RANK_USED)
  316. X        {
  317. X            if (rank < tmp->bid.rank || 
  318. X              rank == tmp->bid.rank &&
  319. X              suit_cvt[suit] <= suit_cvt[tmp->bid.suit])
  320. X            return(1);
  321. X            break;
  322. X        }
  323. X    }
  324. X    /* Make sure double or redouble is valid */
  325. X    else if (suit == DOUBLE || suit == REDOUBLE)
  326. X    {
  327. X    if (pdeal->num_bids <= 0)
  328. X        return(1);
  329. X        for (tmp = pdeal->bids->prev,i = pdeal->num_bids; i;
  330. X      tmp = tmp->prev, i--)
  331. X        if (tmp->bid.suit != PASS)
  332. X        {
  333. X            /* Double or redouble by wrong side */
  334. X        /* The person bidding in the num_bids position was
  335. X           an opponent. The last valid bidder must have had
  336. X           this parity. */
  337. X        if (((i ^ pdeal->num_bids) & 1) == 1)
  338. X            return(1);
  339. X        /* Double of a double or redouble */
  340. X        if (suit == DOUBLE && tmp->bid.suit > RANK_USED)
  341. X            return(1);
  342. X        /* Redouble of a bid other than double */
  343. X        if (suit == REDOUBLE && tmp->bid.suit != DOUBLE)
  344. X            return(1);
  345. X        break;
  346. X        }
  347. X    /* Double or redouble as first non-pass bid */
  348. X    if (!i)
  349. X        return(1);
  350. X    }
  351. X
  352. X    newbid = (bid *)malloc(sizeof(bid));
  353. X    newbid->bid.rank = rank;
  354. X    newbid->bid.suit = suit;
  355. X
  356. X    if (++(pdeal->num_bids) == 1)
  357. X    newbid->next = newbid->prev = pdeal->bids = newbid;
  358. X    else
  359. X    {
  360. X    (newbid->next = pdeal->bids)->prev = 
  361. X      (newbid->prev = pdeal->bids->prev)->next = newbid;
  362. X    if (newbid->bid.suit == PASS && newbid->prev->bid.suit == PASS &&
  363. X      newbid->prev->prev->bid.suit == PASS && pdeal->num_bids >= 4)
  364. X        pdeal->bidding_done = 1;
  365. X    }
  366. X    return(0);
  367. X}
  368. X
  369. Xmore()
  370. X{
  371. X    printf("---Hit return to continue---");
  372. X    while (getchar() != '\n');
  373. X}
  374. X
  375. Xlog_deal(pdeal,top_hand)
  376. Xdeal *pdeal;
  377. Xint top_hand;
  378. X{
  379. X    FILE *fp;
  380. X    int i;
  381. X
  382. X    if ((fp = fopen(LOGFILE,"a")) == NULL)
  383. X    {
  384. X    perror(LOGFILE);
  385. X    return;
  386. X    }
  387. X    print_bidding(fp,pdeal);
  388. X    if (pdeal->opening_lead.suit >= 0)
  389. X        fprintf(fp,"OPENING LEAD: %c of %s\n",pdeal->opening_lead.rank,
  390. X          suit_strings[pdeal->opening_lead.suit]);
  391. X    print_complete_deal(fp,pdeal,top_hand);
  392. X    putc('\n',fp);
  393. X    putc('\n',fp);
  394. X    fclose(fp);
  395. X}
  396. X
  397. Xfigure_out_leader(pdeal)
  398. Xdeal *pdeal;
  399. X{
  400. X    int contract_maker;
  401. X    bid *finalsuit,*tmp;
  402. X    int suit_bidder;
  403. X
  404. X    /* Find out which bid specified the basic contract */
  405. X    for (contract_maker = pdeal->num_bids - 1, finalsuit = pdeal->bids->prev;
  406. X      contract_maker >= 0 && finalsuit->bid.suit > RANK_USED;
  407. X      contract_maker--, finalsuit = finalsuit->prev);
  408. X    if (contract_maker < 0)
  409. X        return(-1);
  410. X    /* Reduce this to a single side */
  411. X    contract_maker &= 1;
  412. X    /* Find the first player of this side to bid this suit. */
  413. X    suit_bidder = contract_maker;
  414. X    tmp = (suit_bidder) ? pdeal->bids->next : pdeal->bids;
  415. X    while (tmp->bid.suit != finalsuit->bid.suit)
  416. X    {
  417. X        suit_bidder += 2;
  418. X    tmp = tmp->next->next;
  419. X    }
  420. X    return((suit_bidder + 1) % 4);
  421. X}
  422. X
  423. Xget_lead(pdeal,handnum)
  424. Xdeal *pdeal;
  425. Xint handnum;
  426. X{
  427. X    int rank,suit,i;
  428. X    char *tmp;
  429. X    static char valid_ranks[] = "23456789TJQKA";
  430. X    static char valid_suits[] = "SHDC";
  431. X    
  432. X    printf("\nEnter your opening lead: ");
  433. X
  434. X    /* Get rank */
  435. X    while (isspace(rank = getchar()));
  436. X
  437. X    /* Get suit */
  438. X    while (isspace(suit = getchar()));
  439. X
  440. X    if (islower(rank))
  441. X        rank = toupper(rank);
  442. X    if (index(valid_ranks,rank) == NULL)
  443. X    {
  444. X        if (rank == '1' && suit == '0')
  445. X    {
  446. X        rank = 'T';
  447. X        /* Get suit again */
  448. X        while (isspace(suit = getchar()));
  449. X    }
  450. X    else
  451. X        rank = -1;
  452. X    }
  453. X    if (islower(suit))
  454. X        suit = toupper(suit);
  455. X    if ((tmp = index(valid_suits,suit)) == NULL)
  456. X        suit = -1;
  457. X    while (getchar() != '\n');
  458. X    if (rank < 0 || suit < 0)
  459. X        return(1);
  460. X
  461. X    pdeal->opening_lead.rank = rank;
  462. X    pdeal->opening_lead.suit = tmp - valid_suits;
  463. X
  464. X    /* Check to see if it's in the hand */
  465. X    for (i = 0; i < 13; i++)
  466. X        if (pdeal->hands[handnum][i].suit == pdeal->opening_lead.suit &&
  467. X      valid_ranks[pdeal->hands[handnum][i].rank - 2] ==
  468. X      pdeal->opening_lead.rank)
  469. X        return(0);
  470. X    return(1);
  471. X}
  472. END_OF_bidding.c
  473. if test 9272 -ne `wc -c <bidding.c`; then
  474.     echo shar: \"bidding.c\" unpacked with wrong size!
  475. fi
  476. # end of overwriting check
  477. fi
  478. if test -f bidding.doc -a "${1}" != "-c" ; then 
  479.   echo shar: Will not over-write existing file \"bidding.doc\"
  480. else
  481. echo shar: Extracting \"bidding.doc\" \(2818 characters\)
  482. sed "s/^X//" >bidding.doc <<'END_OF_bidding.doc'
  483. X            Bridge Bidder Version 1.0
  484. X            by Nathan Glasser
  485. X            nathan@xx.lcs.mit.edu (internet)
  486. X            nathan@mit-eddie.uucp (usenet)
  487. X
  488. X            May, 1988
  489. X------------------------------------------------------------------------------
  490. XCopyright 1988 by Nathan Glasser.
  491. XYou may feel free to distribute this program in its current form.
  492. XPlease do not remove this copyright information.
  493. X==============================================================================
  494. XThis program lets you practice your bidding and opening leads.
  495. X
  496. XAny conventions you want to use are allowed because you're your own
  497. Xpartner, as well as your own opponents. The idea behind this program
  498. Xis that if you're involved with a large enough number of boards, you
  499. Xhopefully won't remember all the hands of a given board, and so you
  500. Xcan bid each of the four hands at different times. What the program
  501. Xdoes is let you make all the bids in all the hands, one bid at a
  502. Xtime, choosing which board to use at any point randomly and letting
  503. Xyou enter the next bid in its bidding sequence.
  504. X
  505. XIn this way, you get to practice bidding with 3 other players whose
  506. Xbidding you understand completely and a partner whom you trust
  507. Ximplicitly. If you find this not to be the case, then you'll probably
  508. Xhave discovered ways in which you need to better understand your
  509. Xbidding system or in which bidding can otherwise be improved.
  510. X
  511. X(By the way, randomly dealt hands tend to have more unusual
  512. Xdistribution than cards which are shuffled and dealt. Thus you may
  513. Xfind that you're pushing your knowledge of your bidding system to its
  514. Xlimits with some of the hands you'll get.)
  515. X------------------------------------------------------------------------------
  516. XThe operation of the program is as follows:
  517. X
  518. XUsage:    bidding [number of boards]
  519. X
  520. XThe number of boards to deal can be specified on the command line; the
  521. Xdefault is 10.
  522. X
  523. XThe appropriate number of boards are dealt.
  524. X
  525. XYou are shown a single hand, and the bidding of the current board so
  526. Xfar (if there's been any), and you get to enter the next bid.
  527. X
  528. XYou continue in this fashion until the bidding is completed on every hand.
  529. X
  530. XThen you are presented with the hand of the player to make the
  531. Xopening lead on a board, and the bidding of the hand, and get to
  532. Xenter the opening lead.
  533. X
  534. XThe complete hand is then presented to you for your analysis.
  535. X
  536. XYou continue in this fashion until all the hands have been bid and led to.
  537. X
  538. XA complete log of each board is automatically written to the file
  539. X"bidding.log" after the board's completion.
  540. X------------------------------------------------------------------------------
  541. XBids are specified in the obvious way, e.g. 1s = 1 spade, 2n = 2 notrump,
  542. Xp = pass, d = double, r = redouble.
  543. X
  544. XSimilarly, opening leads are specified in the obvious way, e.g.
  545. X2c = 2 of clubs, js = jack of spades, th or 10h = ten of hearts.
  546. END_OF_bidding.doc
  547. if test 2818 -ne `wc -c <bidding.doc`; then
  548.     echo shar: \"bidding.doc\" unpacked with wrong size!
  549. fi
  550. # end of overwriting check
  551. fi
  552. if test -f bidding.h -a "${1}" != "-c" ; then 
  553.   echo shar: Will not over-write existing file \"bidding.h\"
  554. else
  555. echo shar: Extracting \"bidding.h\" \(1261 characters\)
  556. sed "s/^X//" >bidding.h <<'END_OF_bidding.h'
  557. X/* bidding.h */
  558. X/*
  559. X            Bridge bidder
  560. X            by Nathan Glasser
  561. X            nathan@xx.lcs.mit.edu (internet)
  562. X            nathan@mit-eddie.uucp (usenet)
  563. X
  564. X            May, 1988
  565. X------------------------------------------------------------------------------
  566. XCopyright 1988 by Nathan Glasser.
  567. XYou may feel free to distribute this program in its current form.
  568. XPlease do not remove this copyright information.
  569. X*/
  570. X
  571. X#include <stdio.h>
  572. X#include <ctype.h>
  573. X#ifdef MSDOS
  574. X#include <string.h>
  575. X#include <stdlib.h>
  576. X#define random rand
  577. X#define srandom srand
  578. X#define index strchr
  579. X#else
  580. X#include <strings.h>
  581. X#endif
  582. X
  583. X#define LOGFILE "bidding.log"
  584. X
  585. X#define JACK 11
  586. X#define QUEEN 12
  587. X#define KING 13
  588. X#define ACE 14
  589. X
  590. X#define SPADES 0
  591. X#define HEARTS 1
  592. X#define DIAMONDS 2
  593. X#define CLUBS 3
  594. X
  595. X#define NOTRUMP 4
  596. X#define RANK_USED 4
  597. X
  598. X#define DOUBLE 5
  599. X#define REDOUBLE 6
  600. X#define PASS 7
  601. X
  602. X
  603. X#define FIRSTPAIR 0
  604. X#define SECONDPAIR 1
  605. X#define RELATIVE 1
  606. X#define NEITHER 2
  607. X#define BOTH 3
  608. X
  609. X
  610. Xstruct card_or_bid {
  611. X    int rank;
  612. X    int suit;
  613. X};
  614. X
  615. Xtypedef struct card_or_bid card;
  616. X
  617. Xtypedef struct bid {
  618. X    struct card_or_bid bid;
  619. X    struct bid *next,*prev;
  620. X} bid;
  621. X
  622. Xtypedef card hand[13];
  623. X
  624. Xtypedef struct deal {
  625. X    hand hands[4];
  626. X    int vulnerability;
  627. X    bid *bids;
  628. X    int num_bids;
  629. X    int bidding_done;
  630. X    card opening_lead;
  631. X} deal;
  632. END_OF_bidding.h
  633. if test 1261 -ne `wc -c <bidding.h`; then
  634.     echo shar: \"bidding.h\" unpacked with wrong size!
  635. fi
  636. # end of overwriting check
  637. fi
  638. if test -f deal.c -a "${1}" != "-c" ; then 
  639.   echo shar: Will not over-write existing file \"deal.c\"
  640. else
  641. echo shar: Extracting \"deal.c\" \(2224 characters\)
  642. sed "s/^X//" >deal.c <<'END_OF_deal.c'
  643. X/* deal.c */
  644. X/*
  645. X            Bridge bidder
  646. X            by Nathan Glasser
  647. X            nathan@xx.lcs.mit.edu (internet)
  648. X            nathan@mit-eddie.uucp (usenet)
  649. X
  650. X            May, 1988
  651. X------------------------------------------------------------------------------
  652. XCopyright 1988 by Nathan Glasser.
  653. XYou may feel free to distribute this program in its current form.
  654. XPlease do not remove this copyright information.
  655. X*/
  656. X
  657. X#include "bidding.h"
  658. X
  659. X
  660. Xcard_compare(pcard1,pcard2)
  661. Xcard *pcard1,*pcard2;
  662. X{
  663. X    return((pcard1->suit != pcard2->suit) ? (pcard1->suit - pcard2->suit) :
  664. X       (pcard2->rank - pcard1->rank));
  665. X}
  666. X
  667. Xdeal_hands(pdeal)
  668. Xdeal *pdeal;
  669. X{
  670. X    card *thehand;
  671. X    int cards[52];
  672. X    int player,cardsinhand;
  673. X    int cardnum;
  674. X    int nextcard;
  675. X    int cardsleft = 52;
  676. X    static vulnerability = 0;
  677. X
  678. X    pdeal->num_bids = 0;
  679. X    pdeal->bidding_done = 0;
  680. X    vulnerability = ((pdeal->vulnerability = vulnerability) + 1) % 4;
  681. X    pdeal->opening_lead.rank = pdeal->opening_lead.suit = -1;
  682. X
  683. X    for (cardnum = 0; cardnum < 52; cardnum++)
  684. X    cards[cardnum] = 0;
  685. X
  686. X    for (player = 0; player < 4; player++)
  687. X    {
  688. X    thehand = pdeal->hands[player];
  689. X    for (cardsinhand = 0; cardsinhand < 13; cardsinhand++)
  690. X    {
  691. X        nextcard = random() % (cardsleft--);
  692. X        for (cardnum = 0 ; cards[cardnum] || --nextcard >= 0; cardnum++);
  693. X        cards[cardnum] = 1;
  694. X        thehand[cardsinhand].suit = cardnum / 13;
  695. X        thehand[cardsinhand].rank = 2 + (cardnum % 13);
  696. X    }
  697. X    qsort(thehand,13,sizeof(card),card_compare);
  698. X    }
  699. X}
  700. X
  701. X
  702. Xprint_hand(fp,thehand)
  703. XFILE *fp;
  704. Xcard *thehand;
  705. X{
  706. X    int i;
  707. X    char bufs[4][80];
  708. X
  709. X    format_hand(bufs,thehand);
  710. X    for (i = 0; i < 4; i++)
  711. X    {
  712. X        fputs(bufs[i],fp);
  713. X    putc('\n',fp);
  714. X    }
  715. X}
  716. X
  717. X/* Accepts an array of size four of strings, and formats into it */
  718. Xformat_hand(bufs,thehand)
  719. Xchar (*bufs)[80];
  720. Xcard *thehand;
  721. X{
  722. X    extern char *suit_strings[];
  723. X    static char card_chars[] = "xx23456789TJQKA";
  724. X    int suit_num = -1;
  725. X    int i;
  726. X    static char card_str[3] = " A";
  727. X
  728. X    bufs--;
  729. X    for (i = 0; i < 13; i++)
  730. X    {
  731. X    while (thehand[i].suit != suit_num)
  732. X        sprintf(*++bufs,"%8s:  ",suit_strings[++suit_num]);
  733. X    card_str[1] = card_chars[thehand[i].rank];
  734. X    strcat(*bufs,card_str);
  735. X    }
  736. X    while (suit_num < 3)
  737. X        sprintf(*++bufs,"%8s:  ",suit_strings[++suit_num]);
  738. X}
  739. END_OF_deal.c
  740. if test 2224 -ne `wc -c <deal.c`; then
  741.     echo shar: \"deal.c\" unpacked with wrong size!
  742. fi
  743. # end of overwriting check
  744. fi
  745. if test -f makefile -a "${1}" != "-c" ; then 
  746.   echo shar: Will not over-write existing file \"makefile\"
  747. else
  748. echo shar: Extracting \"makefile\" \(122 characters\)
  749. sed "s/^X//" >makefile <<'END_OF_makefile'
  750. X#Unix makefile for bridge bidder
  751. X
  752. XOBJS = bidding.o deal.o
  753. X
  754. Xbidding:    $(OBJS)
  755. X    $(CC) $(OBJS) -o bidding
  756. X
  757. X$(OBJS):    bidding.h
  758. END_OF_makefile
  759. if test 122 -ne `wc -c <makefile`; then
  760.     echo shar: \"makefile\" unpacked with wrong size!
  761. fi
  762. # end of overwriting check
  763. fi
  764. echo shar: End of archive 1 \(of 1\).
  765. cp /dev/null ark1isdone
  766. MISSING=""
  767. for I in 1 ; do
  768.     if test ! -f ark${I}isdone ; then
  769.     MISSING="${MISSING} ${I}"
  770.     fi
  771. done
  772. if test "${MISSING}" = "" ; then
  773.     echo You have unpacked all 1 archives.
  774.     rm -f ark[1-9]isdone
  775. else
  776.     echo You still need to unpack the following archives:
  777.     echo "        " ${MISSING}
  778. fi
  779. ##  End of shell archive.
  780. exit 0
  781.